﻿using System.Collections.Generic;
using System.Linq;
using Avalonia.Collections;
using Avalonia.Styling;
using CommunityToolkit.Mvvm.ComponentModel;
using MathPlus.Features;
using MathPlus.Services;

namespace MathPlus.ViewModels;

public partial class MainWindowViewModel : ViewModelBase
{
    [ObservableProperty] private bool _windowLocked;
    [ObservableProperty] private bool _titleBarVisible = true;

    public IAvaloniaReadOnlyList<DemoPageBase> DemoPages { get; }

    [ObservableProperty] private DemoPageBase? _activePage;

    public MainWindowViewModel(IEnumerable<DemoPageBase> demoPages, PageNavigationService pageNavigationService)
    {
        // ToastManager = toastManager;
        // DialogManager = dialogManager;
        DemoPages = new AvaloniaList<DemoPageBase>(demoPages.OrderBy(x => x.Index).ThenBy(x => x.DisplayName));
        // _theming = (ThemingViewModel)DemoPages.First(x => x is ThemingViewModel);
        // _theming.BackgroundStyleChanged += style => BackgroundStyle = style;
        // _theming.BackgroundAnimationsChanged += enabled => AnimationsEnabled = enabled;
        // _theming.CustomBackgroundStyleChanged += shader => CustomShaderFile = shader;
        // _theming.BackgroundTransitionsChanged += enabled => TransitionsEnabled = enabled;
        
        // BackgroundStyles = new AvaloniaList<SukiBackgroundStyle>(Enum.GetValues<SukiBackgroundStyle>());
        // _theme = SukiTheme.GetInstance();
        
        // Subscribe to the navigation service (when a page navigation is requested)
        pageNavigationService.NavigationRequested += pageType =>
        {
            var page = DemoPages.FirstOrDefault(x => x.GetType() == pageType);
            if (page is null || ActivePage?.GetType() == pageType) return;
            ActivePage = page;
        };
        
        // Themes = _theme.ColorThemes;
        // BaseTheme = _theme.ActiveBaseTheme;
        
        // Subscribe to the base theme changed events
        // _theme.OnBaseThemeChanged += variant =>
        // {
        //     BaseTheme = variant;
        //     ToastManager.CreateSimpleInfoToast()
        //         .WithTitle("Theme Changed")
        //         .WithContent($"Theme has changed to {variant}.")
        //         .Queue();
        // };
        
        // // Subscribe to the color theme changed events
        // _theme.OnColorThemeChanged += theme => ToastManager.CreateSimpleInfoToast()
        //     .WithTitle("Color Changed")
        //     .WithContent($"Color has changed to {theme.DisplayName}.")
        //     .Queue();
    }
}
